package apache_commons_utils;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.codec.net.URLCodec;

import java.util.Arrays;
import java.util.BitSet;

/**
 * @author: hu.shengjin
 * @date: 2019/12/5
 * @description: 编码解码方法封装
 */
public class CodecTest {
    public static void main(String[] args) throws Exception {
        //Base64
        System.out.println("======================Base64=====================");
        byte[] binaryData = {1,2,3,4,5};
        String encodeBase64String = Base64.encodeBase64String(binaryData);
        byte[] bytes = Base64.decodeBase64(encodeBase64String);
        System.out.println(encodeBase64String);
        System.out.println(Arrays.toString(bytes));

        System.out.println("======================MD5=====================");
        //MD5
        String data = "12345";
        String md5Hex = DigestUtils.md5Hex(data);
        System.out.println(md5Hex);

        System.out.println("======================URL=====================");
        //URL
        String url = "http://127.0.0.1:8128/cma2/login";
        byte[] urlBytes = url.getBytes();
        byte[] encodeUrl = URLCodec.encodeUrl(new BitSet(), urlBytes);
        byte[] decodeUrl = URLCodec.decodeUrl(encodeUrl);
        System.out.println(Arrays.toString(urlBytes));
        System.out.println(Arrays.toString(encodeUrl));
        System.out.println(Arrays.toString(decodeUrl));
    }
}
